<template>
  <view class="address">
	  <view class="addressItem" v-for="(address,index) of addressList" @click="go('update',address.id)">
	  		<view class="addressContent">
	  			<view style="padding-right: 20rpx;">
	  				{{address.name}}
	  			</view>
	  			<view>
	  				{{address.phone}}
	  			</view>
	  		</view>
	  		<view class="addressContent">
	  			<view v-if="address.preset" class="active" >
	  				默认
	  			</view>
	  			<view style="padding-right: 20rpx;">
	  				{{address.address}}
	  			</view>
				<view>
					{{address.detailAddress}}
				</view>
	  		</view> 
	  </view>
	  
	  <view class="addPath" @click="go('new')" >
	  	新增地址
	  </view>
  </view>
</template>

<script>
import userConfig from '@/common/api/config/userConfig.js'
export default {
  data() {
    return {
		addressList:[]
	}
  },
  created() {
	  this.init();
  },
  onShow() {
  	this.init();
  },
  methods: {
	  go(data,id){
		  switch(data){
			  case 'new':
				  uni.redirectTo({
					url:"/pages/config/updateAddress"
				  })
				  break;
			  case 'update':
				  uni.redirectTo({
					url:"/pages/config/updateAddress?id="+id
				  })
				  break;
		  }
	  },
	  init(){
		  userConfig.gets()
			.then(res=>{
				this.addressList = res.data.list;
			})
	  }
  }
};
</script>
<style>
.address{
	background-color: #fafafa;
	 width:100%;
	
	 height:100%;
}
.addressItem{
	padding-left: 5%;
	border-bottom:2rpx solid #9e9e9e;
}
.addressContent{
	display:flex;
}
.addPath{
	border-radius: 30rpx;
	text-align: center;
	color: white;
	line-height: 100rpx;
	background-color: #66ccff;
	height: 100rpx;
	bottom: 0rpx;
	width: 100%;
	position: fixed;
}
.active{
	height: 55rpx;
	width: 60rpx;
	line-height: 55rpx;
	text-align: center;
	background-color: #66ccff;
	color: #FFFFFF;
	border-radius: 50%;
	font-size: 24rpx;
	margin-right: 20rpx;
}
</style>
